package models

import (
	"github.com/jinzhu/gorm"
	"kop/modules/conquer/entity"
	"time"
)

func CreateReport(dB *gorm.DB, report entity.ConquerReport) error {

	return dB.Create(&report).Error
}

// 击败25名船长以上的记录
//func GetReportsOver25(dB *gorm.DB, serverID int32, limit int) []entity.ConquerReport {
//
//	var now = time.Now()
//	var year, month, day = now.Date()
//	var today = time.Date(year, month, day, 0, 0, 0, 0, time.Local)
//
//	var data []entity.ConquerReport
//	if err := dB.
//		Where(entity.ConquerReport{ServerID: serverID}).
//		Where("win_num >= 5").
//		Where("created_at >= ?", today).Limit(limit).Order("id DESC").Find(&data).Error; err != nil {
//		panic(err)
//	}
//
//	return data
//}

func GetReports(dB *gorm.DB, roleID int32, limit int) []entity.ConquerReport {

	var now = time.Now()
	var year, month, day = now.Date()
	var today = time.Date(year, month, day, 0, 0, 0, 0, time.Local)

	var data []entity.ConquerReport
	if err := dB.
		Where(entity.ConquerReport{RoleID: roleID}).
		Where("created_at >= ?", today).Limit(limit).Order("id DESC").Find(&data).Error; err != nil {
		panic(err)
	}

	return data
}

func DeleteReports(dB *gorm.DB, time time.Time) error {

	return dB.Where("created_at < ?", time).Delete(entity.ConquerReport{}).Error
}
